package org.dreamwork.assistant.tools.persistence.gui;

import org.dreamwork.util.StringUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by game on 2017/8/1
 */
public class IgnoreCaseHashMap<V> extends HashMap<String, V> {
    @Override
    public V put (String key, V value) {
        if (StringUtil.isEmpty (key)) {
            super.put (null, value);
        }
        return super.put (key.toUpperCase (), value);
    }

    @Override
    public void putAll (Map<? extends String, ? extends V> m) {
        for (String key : m.keySet ()) {
            if (!StringUtil.isEmpty (key)) {
                put (key, m.get (key));
            }
        }
    }

    @Override
    public boolean containsKey (Object key) {
        return key != null && super.containsKey (key.toString ().toUpperCase ());
    }

    @Override
    public V get (Object key) {
        if (key == null) {
            return null;
        }

        return super.get (key.toString ().toUpperCase ());
    }
}